package response;

import core.GamePacket;
import core.*;
import java.io.IOException;

/**
 * Response used for authentication
 *
 * @author yiyi, genki, Zoran, Gary
 */
public class ResponseLogin extends GameResponse {

    private GameUser user;
    private GameCharacter character;
    private GameMap map;
    private short status;

    public ResponseLogin() {
        code = Constants.SMSG_AUTH;
    }
    
    public void setCharacter(GameCharacter character) {
        this.character = character;
    }
    /*
    public void setMap(GameMap map) {
        this.map = map;
    }*/

    public void setStatus(short status) {
        this.status = status;        
    }

    public void setUser(GameUser user) {
        this.user = user;
    }

    @Override
    public byte[] createResponse() {
        
        GamePacket packet = new GamePacket(code);
        packet.addUint16(status);

        if (status == 0) {
            /*man-
            if (user.getID() != Constants.BUG_USER_ID) {
                //packet.addUint32(character.getID());*/
                packet.addUint32(2);
                packet.addString("Manori");
                //packet.addString(user.getFirstName());
                packet.addString(user.getLastName());
                packet.addUint16((short)5);
                /*man-
                packet.addUint16(user.getGender());
                packet.addUint16(user.getGender());
                packet.addUint16(user.getLevel());

                packet.addString(character.getName());
                packet.addUint16(character.getClassID());
                packet.addUint16(character.getModelID());
                packet.addUint16(character.getLevel());

                //int exp_min = character.getExperience() - gameServer.getGameExperienceParser().getExperienceTotal(character.getLevel());
                //int exp_max = gameServer.getGameExperienceParser().getExperienceNeeded(character.getLevel());

                //packet.addUint32(exp_min);
                //packet.addUint32(exp_max);

                packet.addUint32(character.getMoney());
                packet.addUint32(character.getHealth());
                packet.addUint32(character.getHealthMax());
                packet.addUint32(character.getAttackMin());
                packet.addUint32(character.getAttackMax());
                packet.addFloat(character.getAttackRange());
                packet.addUint16(character.getDefense());
                packet.addFloat(character.getMoveSpeed());
                packet.addFloat(character.getScale());

                packet.addString(map.getID());
                packet.addUint16(map.getType());

                packet.addFloat(character.getX());
                packet.addFloat(character.getY());
                packet.addFloat(character.getZ());
                packet.addFloat(character.getH());

                //packet.addUint16((short) character.getEquipmentList().size());

                //for (GameItem equipment : character.getEquipmentList().values()) {
                    //packet.addUint16(equipment.getEquipLocation());
                    //packet.addUint16(equipment.getView());
                //}
            //}*/
        }

        return packet.getBytes();
    }
}
